package ru.dadle8;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import ru.dadle8.model.Customer;

import java.util.Properties;

public class ProducerWithSerializer extends AbstractProducer {

    @Override
    public void sendMessages(String topicName) {
        Properties props = getProperties();
        props.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "ru.dadle8.serializers.CustomerSerializer");

        Producer<String, Customer> producer = new KafkaProducer<>(props);
        for (int i = 0; i < 10; i++) {
            Customer customer = new Customer(i, "name" + i);
            producer.send(new ProducerRecord<>(topicName, Integer.toString(i), customer));
        }

        System.out.println("Message sent successfully");
        producer.close();
    }
}
